<?php 
session_start();
if (isset($_POST['name']) && isset($_SESSION['openid'])){
    $openid=$_SESSION['openid'];
	$name=trim(addslashes($_POST['name']));
	$phone=trim(addslashes($_POST['phone']));
	$hao=trim(addslashes($_POST['hao']));
	if (empty($name) || empty($phone) || empty($hao)){
	    echo json_encode(array('s'=>'not'));
	    exit;
	}
	include_once("../c/config.php");
	$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
	if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
	$sql="select id,isok from users where openid='".$openid."'  limit 0, 1";
	$query=$mysqli->query($sql);
	$isok=0;
    if($query->num_rows>0){
        $getUser=$query->fetch_assoc();
        $isok=$getUser['isok'];
        $mysqli->query("update `users` set `name`='".$name."',`phone`='".$phone."',`hao`='".$hao."',`createtime`='".date("Y-m-d H:i:s")."' where openid='".$openid."'");
    }else{
        $mysqli->query("INSERT INTO `users` (`openid`,`name`,`phone`,`hao`,`createtime`) VALUES ('".$openid."','".$name."','".$phone."','".$hao."','".date("Y-m-d H:i:s")."') ");
    }
 
    echo json_encode(array('s'=>$isok));
    $mysqli->close();

}else{
    $msg=json_encode(array('s'=>'ok'));
}
?>